//
//  CZStatusRoolBar.swift
//  WHWeiBo01
//
//  Created by 炜张 on 16/7/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

//微博的toolBar
class CZStatusRoolBar: UIView {
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUp()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //添加按钮
    private lazy var retweetButton: UIButton = self.addChildButton("timeline_icon_retweet",title:"转发")
    private lazy var commentButton: UIButton = self.addChildButton("timeline_icon_comment",title:"评论")
    private lazy var goodButton: UIButton = self.addChildButton("timeline_icon_unlike",title:"赞")
    
    //数据模型
    var statusViewModel: CZStatusViewModel? {
        didSet{
            retweetButton.setTitle(statusViewModel?.retweetStr, forState: .Normal)
            commentButton.setTitle(statusViewModel?.commentStr, forState: .Normal)
            goodButton.setTitle(statusViewModel?.goodStr, forState: .Normal)
            
        }
    }
    
    //设置约束
    private func setUp() {
        //设置按钮的约束
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton)
            
        commentButton.snp_makeConstraints(closure: { (make) -> Void in
            make.leading.equalTo(retweetButton.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(goodButton)
            
            goodButton.snp_makeConstraints(closure: { (make) -> Void in
                make.trailing.equalTo(self)
                make.top.equalTo(self)
                make.bottom.equalTo(self)
                make.leading.equalTo(commentButton.snp_trailing)
                
            })
            
            //添加线
            let firstLabel = addChildLine()
            let twoLabel = addChildLine()
            //设置图片约束
            firstLabel.snp_makeConstraints(closure: { (make) -> Void in
                make.centerX.equalTo(retweetButton.snp_trailing)
                make.centerY.equalTo(self)
            })
            
            twoLabel.snp_makeConstraints(closure: { (make) -> Void in
                make.centerX.equalTo(commentButton.snp_trailing)
                make.centerY.equalTo(self)
                
            })
            
        })
        }
    }
    

    
//    按钮中间的竖线
    private func addChildLine() -> UIImageView {
        let imageView = UIImageView(image: (UIImage(named: "timeline_card_bottom_line")))
        //添加控件
        addSubview(imageView)
        
        return imageView
        
    }
    
    
    //创建按钮的公共方法
    private func addChildButton(imageName: String,title:  String) -> UIButton {
        
        let button = UIButton()
        
        //设置图片
        button.setImage(UIImage(named: imageName), forState: .Normal)
        //取消高亮
        button.adjustsImageWhenHighlighted = false
        
        //设置文字
        button.setTitle(title, forState: .Normal)
        //设置文字大小
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        //设置文字颜色
        button.setTitleColor(UIColor.grayColor(), forState: .Normal)
        
        
        //添加按钮
        addSubview(button)
        
        return button
    }
    
    
    
}










